package ru.spb.osll.myfit.server.execute;

import static org.junit.Assert.assertEquals;

import java.util.List;
import java.util.Vector;

import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;

import ru.spb.osll.myfit.common.Table;
import ru.spb.osll.myfit.common.TableCell;
import ru.spb.osll.myfit.fixtures.base.OneLineFixtureUtilsTest;
import ru.spb.osll.myfit.server.parser.TableParser;
import fit.Parse;

public class FixtureListenerImplTest {
	public FixtureListenerImpl listener;
	private Table returnTable;
	private TableParser tableParser;

	@Before
	public void setUp() {
		tableParser = EasyMock.createMock(TableParser.class);
		listener = new FixtureListenerImpl(tableParser);
		returnTable = new Table();
		Vector<TableCell> tableCells = new Vector<TableCell>();
		tableCells.add(new TableCell("dummy one line"));
		tableCells.add(new TableCell("OK"));
		returnTable.addLine(tableCells);
	}

	@Test
	public void testTableFinished() throws Exception {
		Parse table = new Parse(OneLineFixtureUtilsTest
				.wiki2html("|dummy one line|OK|"));
		EasyMock.expect(tableParser.parse(table)).andReturn(returnTable);
		EasyMock.replay(tableParser);
		listener.tableFinished(table);
		List<Table> tables = listener.getTables();
		assertEquals(1, table.size());
		assertEquals(returnTable, tables.get(0));
		EasyMock.verify(tableParser);
	}
}
